import got from "got";
import moment from "moment";
import { readFileByType } from "./util";

const prefixUrl = process.env.ICAN_PREFIXURL;
const postTaskUrl = process.env.ICAN_POST_TASK;
const token = readFileByType('access_token')

class TaskDTO {
  constructor(title: string) {
    this.title = title
  }
  finishTime = moment().add(7, 'day').format('YYYY-MM-DD HH:mm:ss') // "2020-09-02 23:59:59"
  orgId = 796
  title = "" //测试站添加微信支付
  userSet = []
}


const postTask = async (taskTitle: string) => {
  const headers = {
    authorization: `Bearer ${token}`
  }
  const postUrl = `${prefixUrl}${postTaskUrl}`;
  const taskDto = new TaskDTO(taskTitle)
  try {
    const res = await got.post(postUrl, {
      method: "POST",
      headers,
      json: taskDto
    });
    return res;
  } catch (error) {
    console.error(error);
  }
}

export { postTask }